package com.nulldev.util.threading.event;

public class EventSourceImpl implements EventSource {
    
    private EventQueue eventQueue;
    
    public EventQueue getEventQueue() {
        return eventQueue;
    }
    
    public void setEventQueue(EventQueue queue) {
        if (this.eventQueue != null)
            throw new RuntimeException("An event queue already bound to this object.");
        this.eventQueue = queue;
    }
    
    public void removeEventQueue() {
        eventQueue = null;
    }
    
    @Override
    public boolean postEvent(Event event) {
        if (eventQueue == null)
            return false;
        
        eventQueue.post(event);
        return true;
    }
}
